// 登录页面
const app = getApp();
const util = require("../../../utils/util.js");
var getUserInfo;
let type;
Page({

    /**
     * 页面的初始数据
     */
    data: {

    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        type = options.type;
        util.getUrl(app.globalData.url);
    },

    getuserinfo(e) {
        ks.getUserInfo({
            withCredentials: true,
            success: res =>{
                
                ks.setStorageSync("userInfo", res.userInfo)
                let loginData = {
                    action: "ks_userInfo",
                    session_key: ks.getStorageSync("session_key"),
                    encryptedData: res.encryptedData,
                    iv: res.iv,
                    openid: ks.getStorageSync('openid') || '',
                    // unionid: ks.getStorageSync('unionid') || ''
                };
                util.request('user.php', loginData, 'POST').then(res => {
                    if (res.data.state == 1) {
                        ks.setStorageSync("user_id", res.data.data.user_id);
                        ks.navigateBack({
                            delta: 1
                        });
                    }else
                    ks.showToast({
                        title: '登录失败，请检查快手是否更新到最新版',
                        icon: 'none',
                    });
                });
            },
            fail: () => {
                ks.showToast({
                    title: '请授权后再登录',
                    icon: 'none',
                });
            }
        })
  
    },
});